#include "name_pipe.hpp"

int main()
{
    bool r = create_fifo(NAME_PIPE);
    assert(r);
    (void)r;

    std::cout << "server begin" << std::endl;
    int rdid = open(NAME_PIPE, O_RDONLY);

    char buffer[1024] = {0};
    while (1)
    {
        ssize_t s = read(rdid, buffer, sizeof(buffer));
        if (s > 0)
        {
            buffer[s] = '\0';
            std::cout << "client -> server : " << buffer << std::endl;
        }
        else if (s == 0)
        {
            std::cout << "client write close " << std::endl;
            break;
        }
        else
        {
            std::cout << "server read failed" << std::endl;
            break;
        }
    }
    close(rdid);
    remove_fifo(NAME_PIPE);
    std::cout << "server endl" << std::endl;

    return 0;
}
